import kmeans
import kmeansplusplus
import fuzzy
import one
import time
import pandas
import sys
import datetime
import pickle
import multiprocessing
from pympler import asizeof
funclist=['kmeans.kmeans','kmeansplusplus.KMeansPlusPlus','fuzzy.FuzzyKMeans','one.One']
data = pandas.read_excel('dataset.xlsx', header=None)[2]
k=4
i=100
def train(i):
    res = {
        'i': [],
        'time': [],
        'sse': [],
        'memory': [],
    }
    a = time.perf_counter_ns()
    f = eval(i + "(k,data)")
    b = time.perf_counter_ns() - a
    res["i"].append(0)
    res["time"].append(b)
    res["sse"].append(0)
    res['memory'].append(asizeof.asizeof(f))
    print(b)
    for j in range(1, 101):
        a = time.perf_counter_ns()
        f.fit()
        b = time.perf_counter_ns() - a
        print(b)
        res["i"].append(j)
        res["time"].append(b)
        res["sse"].append(f.getsse())
        res['memory'].append(asizeof.asizeof(f))
    res = pandas.DataFrame(res)
    res.to_excel("./data/" + i + ".xlsx", index=False)
    file=open(str(i),"wb")
    pickle.dump(f,file)
    print("success "+str(i))
if __name__ == '__main__':
    print("start")
    for i in range(len(funclist)):
         train(funclist[i])